package cn.com.xxlibrary.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import cn.com.xxlibrary.dao.IManagerDao;
import cn.com.xxlibrary.orm.ManagerInfoBean;
import cn.com.xxlibrary.service.IManagerService;
import cn.com.xxlibrary.util.UtilTools;

@Service
@Repository("manService")
public class ManagerServiceImpl implements IManagerService {

	@Resource
	IManagerDao manDao;

	public ManagerInfoBean login(ManagerInfoBean manager) {
		if (UtilTools.isNotNullorEmpty(manager)) {
			return manDao.login(manager);
		} else {
			return null;
		}
	}

	@Override
	public void addManager(ManagerInfoBean manager) {
		if (UtilTools.isNotNullorEmpty(manager)) {
			manager.setManPassword("d6a9a933c8aafc51e55ac0662b6e4d4a");
			manDao.addManager(manager);
		}
	}

	@Override
	public void changeManager(int id, int state) {
		if (!(id<0)){
			manDao.changeManager(id, state);
		}
	}

	@Override
	public void delManager(int id) {
		if (id>=0){
			manDao.delManager(id);
		}
	}

	@Override
	public Map listManager(int start, int pageSize) {
		return manDao.listManager(start,pageSize);
	}

	@Override
	public ManagerInfoBean queManager(int id) {
		if (id>=0){
			ManagerInfoBean manager = manDao.queManager(id);
			return manager;
		}else{
			return null;
		}
	}

	@Override
	public void changePwd(ManagerInfoBean manager, String newPwd) {
		manager.setManPassword(newPwd);
		manDao.changePwd(manager);
	}
	
	@Override
	public List listManagerType(){
		return manDao.listManagerType();
	}
	
	@Override
	public void resetPwd(int id, String pwd){
		ManagerInfoBean manager = manDao.queManager(id);
		manager.setManPassword(pwd);
		manDao.updataManager(manager);
	}
	
}
